// Author: Wilfred Pinto
// Website: http://projectsilverlight.blogspot.com

using System;
using System.Windows;
using System.Windows.Media;

namespace SimpleViewer_SL.code
{
    /// <summary>
    /// The object to store the initialization values that are passed at startup
    /// </summary>
    public class InitializationSettings
    {
        /// <summary>
        /// Relative or absolute URL of the gallery XML file. 
        /// Relative paths are relative to the HTML page that contains the xap
        /// </summary>
        public string XmlDataPath { get; private set; }
        
        /// <summary>
        /// Index of image to display when gallery loads. 
        /// Images are numbered beginning at zero. 
        /// You can use this option to display a specific number based on the URL
        /// </summary>
        public int FirstImageIndex { get; private set; }
        
        /// <summary>
        /// The text displayed for the right-click 'Open Image in New Window' menu option. 
        /// Can be used to translate SimpleViewer-SL into a non-English language
        /// </summary>
        /// <remarks>Currently not supported!</remarks>
        public string LangOpenImage { get; private set; }
        
        /// <summary>
        /// The text displayed for the right-click 'About' menu option. 
        /// Can be used to translate SimpleViewer-SL into a non-English language
        /// </summary>
        /// <remarks>Currently not supported!</remarks>
        public string LangAbout { get; private set; }
        
        /// <summary>
        /// Preloader color (hexadecimal color value)
        /// </summary>
        public Color PreloaderColor { get; private set; }

        /// <summary>
        /// Initializes a new instance of the <c>InitializationSettings</c> class
        /// </summary>
        public InitializationSettings()
        {
            // Default values for all startup parameters
            XmlDataPath = "gallery.xml";
            FirstImageIndex = 0;
            LangOpenImage = "Open Image in New Window";
            LangAbout = "About";
            PreloaderColor = Color.FromArgb(255, 255, 255, 255); // white
        }

        /// <summary>
        /// Parses the startup parameters passed to the application
        /// </summary>
        /// <param name="e">Contains the event data for the System.Windows.Application.Startup event</param>
        public void LoadInitializationParams(StartupEventArgs e)
        {
            string param;

            // Store value of xmlDataPath (string) parameter
            if (e.InitParams.TryGetValue("xmlDataPath", out param))
                XmlDataPath = SettingsHelper.GetAttributeStringWithDefault(param, XmlDataPath);

            // Store value of firstImageIndex (integer) parameter
            if (e.InitParams.TryGetValue("firstImageIndex", out param))
                FirstImageIndex = SettingsHelper.GetAttributeIntWithDefault(param, FirstImageIndex);

            // Store value of langOpenImage (string) parameter
            if (e.InitParams.TryGetValue("langOpenImage", out param))
                LangOpenImage = SettingsHelper.GetAttributeStringWithDefault(param, LangOpenImage);

            // Store value of langAbout (string) parameter
            if (e.InitParams.TryGetValue("langAbout", out param))
                LangAbout = SettingsHelper.GetAttributeStringWithDefault(param, LangAbout);

            // Store value of preloaderColor (hex color) parameter
            if (e.InitParams.TryGetValue("preloaderColor", out param))
                PreloaderColor = SettingsHelper.HexStringToColorWithDefault(param, PreloaderColor);
        }
    }
}


